﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.ComponentModel;

namespace Scheduler
{
    internal class WorkItemQueueHandler
    {
        internal ThreadStart _threadStart;
        internal Thread _workerThread;
        internal int _handlesQueueNumber;
        private SchedulingEngine _schedulingEngine;

        public WorkItemQueueHandler(SchedulingEngine engine, int handlesQueueNumber)
        {
            _schedulingEngine = engine;
            _handlesQueueNumber = handlesQueueNumber;
        }

        public void HandleAndExecuteWorkItems()
        {
            _schedulingEngine.HandleWorkItemQueue(_handlesQueueNumber);
        }

        public void StartEventHandler()
        {
            _threadStart = new ThreadStart(HandleAndExecuteWorkItems);
            _workerThread = _threadStart.CreateAndRunThread();
        }

        private ThreadSafeQueue<IExecutableWorkItem> AssociatedWorkItemQueue
        {
            get
            {
                return _schedulingEngine._allWorkItemQueues[_handlesQueueNumber];
            }
        }
    }
}
